package com.mbengue.corp.artisan.vue.fenetre;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Chercher extends JFrame {
  private static final long serialVersionUID = -1387122077608510913L;
  private final JTextField texte;
  private final JButton rechercher;
  private final JButton annuler;

  public Chercher(String nomRecherche, String textIndication) {
    super(nomRecherche);
    this.setSize(400, 300);
    this.setLocationRelativeTo(null);
    JPanel panneau = new JPanel();
    JLabel indication = new JLabel(textIndication);
    this.texte = new JTextField(30);

    panneau.add(indication, BorderLayout.EAST);
    panneau.add(this.texte, BorderLayout.WEST);
    this.getContentPane().add(panneau, BorderLayout.CENTER);
    this.rechercher = new JButton("Rechercher");
    this.annuler = new JButton("Annuler");
    JPanel panneau2 = new JPanel();
    panneau2.add(this.rechercher, BorderLayout.WEST);
    panneau2.add(this.annuler, BorderLayout.EAST);
    this.getContentPane().add(panneau2, BorderLayout.SOUTH);

    this.ajouterEcouteurs();
    this.setVisible(true);
  }

  private void ajouterEcouteurs() {
    this.annuler.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        dispose();
        setVisible(false);
      }
    });
  }

  public JButton getRechercher() {
    return rechercher;
  }

  public JButton getAnnuler() {
    return annuler;
  }

  public JTextField getTexte() {
    return texte;
  }
}
